package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.BuyBean;
import com.project.bean.UserBean;
import com.project.service.IBuyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("buy")
@Api(tags="采购订单控制器")
public class BuyController {
    @Autowired
    private IBuyService buyService;
    @ApiOperation("添加采购订单")
    @RequestMapping("add")
    @RequiresPermissions("buy:add")
    public String add(BuyBean buy, HttpServletRequest req) {
        UserBean loginUser = (UserBean) req.getSession().getAttribute("loginUser");
        buyService.add(buy, loginUser.getId());
        return "ok";
    }
    @ApiOperation(value ="动态分页查询采购订单",notes = "按页码，供应商名、起始日期，结束日期查询采购信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="pageNO",value = "页码",required = true),
            @ApiImplicitParam(name="supplier",value = "供应商名"),
            @ApiImplicitParam(name="startDate",value = "起始日期"),
            @ApiImplicitParam(name="endDate",value = "结束日期")
    })
    @RequiresPermissions("buy:find")
    @RequestMapping("cutByItem")
    public IPage<BuyBean> cutByItem(Integer pageNO, String supplier, LocalDate startDate, LocalDate endDate) {
        return buyService.cutByItem(pageNO, supplier, startDate, endDate);
    }
    @ApiOperation("按编号查询订单信息")
    @ApiImplicitParam( name="id",value = "订单编号")
    @RequestMapping("findById")
    @RequiresPermissions("buy:find")
    public BuyBean findById(Integer id) {
        return buyService.findById(id);
    }
}
